package cn.tedu.car.backend.vehicle.service.impl;

import cn.tedu.car.backend.base.response.PageData;
import cn.tedu.car.backend.vehicle.mapper.VehicleMapper;
import cn.tedu.car.backend.vehicle.pojo.dto.StationInfoQuery;
import cn.tedu.car.backend.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.car.backend.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.car.backend.vehicle.pojo.entity.StationInfo;
import cn.tedu.car.backend.vehicle.pojo.entity.Vehicle;
import cn.tedu.car.backend.vehicle.pojo.vo.StationInfoVO;
import cn.tedu.car.backend.vehicle.pojo.vo.VehicleVO;
import cn.tedu.car.backend.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Slf4j
@Service
public class VehicleServiceImpl implements VehicleService {
    @Autowired
    VehicleMapper vehicleMapper;
    @Override
    public PageData selectVehicle(VehicleQuery vehicleQuery) {
        log.debug("查询车辆信息vehicleQuery={}",vehicleQuery);
        List<VehicleVO> list=vehicleMapper.selectVehicle(vehicleQuery);
        PageData pageData = new PageData();
        //向PageData对象中装存入总记录数
        pageData.setList(list);
        pageData.setTotal(vehicleMapper.selectVehicleCount(vehicleQuery));
        //返回封装好的对象
        return pageData;
    }

    @Override
    public void saveVehicle(VehicleSaveParam vehicleSaveParam) {
        Vehicle vehicle=new Vehicle();
        BeanUtils.copyProperties(vehicleSaveParam,vehicle);
        if(vehicle.getId()==null){
            vehicleMapper.insert(vehicle);
        }else {
            vehicleMapper.update(vehicle);
        }
    }

    @Override
    public void deleteVehicle(Long id) {
        vehicleMapper.deleteById(id);
    }

    @Override
    public List<StationInfoVO> selectStation(StationInfoQuery stationInfoQuery) {
        log.debug("查询站点信息StationInfoQuery={}",stationInfoQuery);
        List<StationInfoVO> list=vehicleMapper.selectStation(stationInfoQuery);
        return list;
    }
}

